package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.BaseContext;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
   OrderService orderService;
    @PostMapping("/submit")
    public R dingDan(@RequestBody Orders orders){
       orderService.submit(orders);
        return R.success("订单生成");
    }
    @GetMapping("/userPage")
    public R page(Integer page,Integer pageSize){
        IPage<Orders> pages=new Page<>(page,pageSize);
        QueryWrapper<Orders> qw=new QueryWrapper<>();
        Long userid = BaseContext.getCurrentId();
        qw.lambda().eq(Orders::getUserId,userid);
        orderService.page(pages,qw);
        return R.success(pages);
    }
}
